<?php namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Projects extends Model {

	//
	protected $table = 'projects';

	protected $fillable = ['uid', 'name', 'type_id', 'investment_scale', 'content', 'energy_type_id', 'transform_before', 'transform_after', 'save_effect', 'start_time', 'end_time', 'investment_type_id', 'is_request_award', 'is_request_subsidy', 'is_request_rebate', 'province', 'city', 'area', 'address','is_financing', 'description', 'image', 'save_require', 'efficiency', 'verify_state','index_order',];

	public function investmentType()
	{
		return $this->hasOne("App\Models\InvestmentType", "id", "investment_type_id");
	}

	public function projectDomain()
	{
		return $this->hasMany("App\Models\ProjectDomain", "project_id", "id");
	}

	public function projectTech()
	{
		return $this->hasMany("App\Models\ProjectTech", "project_id", "id");
	}

	public function user()
	{
		return $this->hasOne("App\Models\Users", "id", "uid");
	}

	public function energyType()
	{
		return $this->hasOne("App\Models\EnergyTypes", "id", "investment_type_id");
	}

	public function province()
	{
		return $this->hasOne("App\Models\Area", "area_id", 'province');
	}

	public function city()
	{
		return $this->hasOne("App\Models\Area", "area_id", "city");
	}

	public function area()
	{
		return $this->hasOne("App\Models\Area", "area_id", "area");
	}

	public function projectProgress()
	{
		return $this->hasMany("App\Models\ProjectProgress", "project_id", "id");
	}

	public function biddings()
	{
		return $this->hasMany("App\Models\ProjectBidding", "project_id", "id");
	}

	public function mainBody()
	{
		return $this->hasMany("App\Models\ProjectMainBody", "project_id", "id");
	}

	public function technologies()
	{
		return $this->hasMany("App\Models\ProjectTechnologies", "project_id", "id");
	}

	public function devices()
	{
		return $this->hasMany("App\Models\ProjectDevice", "project_id", "id");
	}

	public function financing()
	{
		return $this->hasOne("App\Models\Financing", "related_id", "id")->where("type", env("FINANCING_PROJECT"));
	}

	public function bidding()
	{
		return $this->hasOne("App\Models\ProjectBidding", "project_id", "id")->where("is_chosen", 1);
	}


}
